package com.lanou.myapp.book.girlbook;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.myapp.R;
import com.lanou.myapp.book.boybook.contentboybook.ContentBoyBookActivity;
import com.lanou.myapp.imageloader.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class GirlBookAdapter extends RecyclerView.Adapter<GirlBookAdapter.MyViewHolder>{
    private Context context;
    private List<GirlBookBeans.GroupEntity> data;

    public GirlBookAdapter(Context context) {
        this.context = context;
    }


    public void addData(List<GirlBookBeans.GroupEntity> data){
        this.data = data;
        notifyDataSetChanged();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = null;
        View view = LayoutInflater.from(context).inflate(R.layout.item_girl_book,null);
        myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.rl_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ContentGirlBookActivity.class);
                intent.putExtra("key", data.get(position).getData().get(0).getBookId());
                context.startActivity(intent);
            }
        });

        holder.rl_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ContentGirlBookActivity.class);
                intent.putExtra("key", data.get(position).getData().get(1).getBookId());
                context.startActivity(intent);
            }
        });

        holder.rl_3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ContentGirlBookActivity.class);
                intent.putExtra("key", data.get(position).getData().get(2).getBookId());
                context.startActivity(intent);
            }
        });

        holder.tv_title.setText(data.get(position).getTitle());
        holder.tv_subtitle.setText(data.get(position).getSubtitle());
        holder.tv_name1.setText(data.get(position).getData().get(0).getBookName());
        holder.tv_name2.setText(data.get(position).getData().get(1).getBookName());
        holder.tv_name3.setText(data.get(position).getData().get(2).getBookName());
    }




    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_title, tv_subtitle;
        private TextView tv_name1, tv_name2, tv_name3;
        private ImageView iv_pic, iv_pic2, iv_pic3;
        private RelativeLayout rl_1, rl_2, rl_3;

        public MyViewHolder(View itemView) {
            super(itemView);

            rl_1 = (RelativeLayout) itemView.findViewById(R.id.relativeLayout1_girl);
            rl_2 = (RelativeLayout) itemView.findViewById(R.id.relativeLayout2_girl);
            rl_3 = (RelativeLayout) itemView.findViewById(R.id.relativeLayout3_girl);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title_girl_book);
            tv_subtitle = (TextView) itemView.findViewById(R.id.tv_subtitle_girl_book);
            tv_name1 = (TextView) itemView.findViewById(R.id.tv_name_girl_book);
            tv_name2 = (TextView) itemView.findViewById(R.id.tv_name2_girl_book);
            tv_name3 = (TextView) itemView.findViewById(R.id.tv_name3_girl_book);
            iv_pic = (ImageView) itemView.findViewById(R.id.tv_img_girl_book);
            iv_pic2 = (ImageView) itemView.findViewById(R.id.tv_img2_girl_book);
            iv_pic3 = (ImageView) itemView.findViewById(R.id.tv_img3_girl_book);

        }
    }
}
